package com.jappit.runtracker.utils;

import java.util.Calendar;
import java.util.Date;

public class FormatUtils
{
	public static String formatDateTime(Date d)
	{
		Calendar c = Calendar.getInstance();
		c.setTime(d);
		
		return twoDigits(c.get(Calendar.DAY_OF_MONTH)) + "/" + twoDigits(c.get(Calendar.MONTH) + 1) + "/" + c.get(Calendar.YEAR) + " at " + 
		twoDigits(c.get(Calendar.HOUR_OF_DAY)) + ":" + twoDigits(c.get(Calendar.MINUTE));
	}
	public static String formatDuration(long millisecs)
	{
		millisecs /= 1000;
		
		long hours = millisecs / 3600;
		
		millisecs -= hours * 3600;
		
		long minutes = millisecs / 60;
		
		millisecs -= minutes * 60;
		
		long seconds = millisecs;
		
		return twoDigits(hours) + ":" + twoDigits(minutes) + ":" + twoDigits(seconds);
	}
	public static String formatDistance(double meters)
	{
		if(meters > 1000)
		{
			return new StringBuffer().append(Math.floor(meters) / 1000).append(" Km").toString();
		}
		else
		{
			return new StringBuffer().append(Math.floor(meters)).append(" mt").toString();
		}
	}
	public static String formatSpeed(double speed)
	{
		return new StringBuffer().append(Math.floor(speed) / 1000).append(" Km/h").toString();
	}
	static String twoDigits(long l)
	{
		if(l < 10)
			return "0" + l;
		else return new StringBuffer().append(l).toString();
	}
}
